﻿using Mono.Cecil;

namespace MethodCaching.Weaving.Extensions
{
    /// <summary>
    /// Extends the <see cref="MethodReference"/> class.
    /// </summary>
    public static class MethodReferenceExtensions
    {
        /// <summary>
        /// Creates a new <see cref="GenericInstanceMethod"/>
        /// </summary>
        /// <param name="methodReference">The target <see cref="MethodReference"/>.</param>
        /// <param name="genericArguments">The list of generic arguments</param>
        /// <returns><see cref="GenericInstanceMethod"/></returns>
        public static GenericInstanceMethod MakeGenericInstanceMethod(this MethodReference methodReference, params TypeReference[] genericArguments)
        {
            var genericInstanceMethod = new GenericInstanceMethod(methodReference);
            foreach (var genericArgument in genericArguments)
                genericInstanceMethod.GenericArguments.Add(genericArgument);
            return genericInstanceMethod;            
        }
    }
}
